package com.bsdk.install.device.socket.v1.cmd;

import com.alibaba.fastjson2.JSONObject;
import com.bsdk.common.utils.StringUtils;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.Objects;

/**
 * @projectName: lock
 * @package: com.hlslock.lock.cmd
 * @className: Cmd
 * @author: HansYoung
 * @description: TODO
 * @date: 2023/12/6 14:14
 * @version: 1.0
 */

@NoArgsConstructor
@Getter
public class COMMAND extends Cmd {
    byte[] data = new byte[100];
    /*


    /*
    获取开关灯的状态
     */
    public String Sw_Get_Local_Key_Status() {
        int j;
        j = 0;
        data[j++] = SOCKET_GET_LOCAL_KEY_STATUS;//查询
        return pack_crc(data, j);
    }
    /*

    逻辑按键，
    执行时：  //0x10表示本地开关，不加表示情景开关
    public static final byte  SOCKET_ACTION_OFF_CMD = 0x00; //关灯
    public static final byte  SOCKET_ACTION_ON_CMD = 0x01; //开灯
    public static final byte  SOCKET_ACTION_TRIGLE_CMD = 0x02; //模拟按键
     */
    public String Sw_Local_Single_Key(byte type,byte logic_key,byte exe) {
        int j;
        int i_tmp = 0;
        j = 0;
        data[j++] = SOCKET_SET_SINGLE_KEY_CMD;// 0x15;
        //0x10表示本地开关，不加表示情景开关
        if(type == SOCKET_TYPE_SINGLE_LINE) //单火开关
        {
            data[j++] = logic_key;
        }
        else//零火开关
        {
            i_tmp = logic_key + 0x10;
            data[j++] = (byte)i_tmp;
        }
        data[j++] = exe;
        return pack_crc(data, j);

    }

    /**
     * 物理按键
     * @param status
     * @param exe
     * @return
     */
    public String Sw_Local_All_Key(byte status,byte exe) {
        int j;
        j = 0;
        data[j++] = SOCKET_SET_ALL_KEY_CMD;// 0x14;
        data[j++] = (byte)status;
        data[j++] = (byte)exe;
        return pack_crc(data, j);
    }
    //一下是与LORA模块的通讯，协议是不一样的
    public String Moudle_Ping() {
        return "02010078ADFF";
    }
    public String Module_Register() {
        return "02010077ECFF";
    }
    //  FROM GateWay:{ "fMac":"0050C262C21E","cMac":"0000e0357feb","type":"0220","time":"230105121009"}
    public String Module_Register(String gw_mac) {
        int j = 0;
        int i;
        int len;
        byte [] mac = new byte[12];
        j = 0;
        len = gw_mac.length();
        if(len!=12)return "FFFF"; //需要写一下
        mac = toBytes(gw_mac);
        data[j++] = CHILD_SET_MASTER_ADDR_CMD;//注册模块查询
        for(i = 0;i<6;i++)data[j++] = mac[i];
        return pack_crc(data, j);
    }

    public String Module_Get_Register_Info() {
        int j = 0;
        //    private static final byte  CHILD_SET_MASTER_ADDR_CMD = (byte) 0x7E; //注册模块
        //   private static final byte  CHILD_REQ_MASTER_ADDR_CMD = (byte) 0x7F; //查询模块注册

        j = 0;
        data[j++] = CHILD_REQ_MASTER_ADDR_CMD;//注册模块查询
        return pack_crc(data, j);
    }

}
